/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kungkhies.desktop.kungkhie.template.explorer;

import com.kungkhies.desktop.library.entities.Kungkhie;
import java.beans.IntrospectionException;
import java.util.List;
import org.openide.nodes.BeanNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.lookup.Lookups;

/**
 *
 * @author clayton
 */
public class KungkhieTemplateChildFactory extends ChildFactory<Kungkhie>
{
    private List<Kungkhie> resultList;

    public KungkhieTemplateChildFactory(List<Kungkhie> resultList)
    {
        this.resultList = resultList;
    }

    @Override
    protected boolean createKeys(List<Kungkhie> list)
    {
        for (Kungkhie Kungkhie : resultList)
        {
            list.add(Kungkhie);
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(Kungkhie c)
    {
        try
        {
            return new KungkhieTemplateBeanNode(c);
        }
        catch (IntrospectionException ex)
        {
            Exceptions.printStackTrace(ex);
            return null;
        }
    }

    private class KungkhieTemplateBeanNode extends BeanNode
    {
        public KungkhieTemplateBeanNode(Kungkhie bean) throws IntrospectionException
        {
            super(bean, Children.LEAF, Lookups.singleton(bean));
        }
    }
}
